#!/usr/bin/perl -w
package node::proc_count;

use Config;

sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self  = {};
my $name=shift;

	if($Config{osname} ne "hpux" && $Config{osname} ne "linux") {
		::warnmsg("Currently only works on HP-UX/Linux!") if defined(&::warnmsg);
		return undef;
	}
	$self->{name}=$name;
	$self->{min_interval}=30;
	$self->{description}="Process count monitor";
	bless ($self, $class);
	return($self);
}

sub action_args {
my $self=shift;

	return "occurrence_minmax";

}

sub min_interval {
my $self=shift;

	return $self->{min_interval};
}

#################################################################
# Since action_args is "threshold" we return a % value - i.e.	#
# a number between 0 and 100 inclusive.				#
#################################################################

sub test {
my $self=shift;

	if($Config{osname} eq "linux") {
		if(! -d "/proc") {
			::warnmsg("The '/proc' directory can not be found.");
			return(0);
		}
		my $fd;
		if(!opendir($fd,"/proc")) {
			::warnmsg("The '/proc' directory can not be opened.");
			return(0);
		}
		my $p=0;
		while($_=readdir($fd)) {
			$p++ if /^\d+$/;
		}
		closedir($fd);
		return $p;
	}
	my ($d,$fd);
	if(!open($fd,"/usr/bin/ps|")) {
		::warnmsg("Unable to run the 'ps' command.") if defined(&::warnmsg);
		return(0);
	}
	my @F;
	@F=<$fd>; close($fd);
	return scalar(@F)-1;
}

sub reset {
my $self=shift;

}

sub desc {
my $self=shift;

	return $self->{description};
}

1;

